package com.itcast.activiti.controller;


import cn.itcast.ic.common.bean.Response;
import cn.itcast.ic.pmis.sdk.DictValueApi;
import cn.itcast.ic.pmis.sdk.domain.DictValue;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;

@RestController
@RequestMapping("/business/system")
public class BusinessLineController {
    @Autowired
    private DictValueApi dictValueApi;

    /**
     * 获取业务系统下拉框
     *
     * @return
     */
    @GetMapping("/options")
    public Response options() {
        Response list1 = dictValueApi.list(new DictValue(), "BUSINESS_SYSTEM");
        List<SortedMap<String, String>> list = new ArrayList<>();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(list1.getData()));
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = (JSONObject) jsonArray.get(i);
            SortedMap<String, String> map = new TreeMap<>();
            map.put("key", jsonObject.getString("number"));
            map.put("value", jsonObject.getString("name"));
            list.add(map);
        }
//        List<SortedMap<String, String>> list = new ArrayList<>();
//        SortedMap<String, String> map1 = new TreeMap<>();
//        map1.put("key", "PMIS");
//        map1.put("value", "PMIS");
//        SortedMap<String, String> map2 = new TreeMap<>();
//        map2.put("key", "OTHER");
//        map2.put("value", "其它");
//        list.add(map1);
//        list.add(map2);
        return Response.success(list);
    }

}

